/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import java.util.ArrayList;
import javax.swing.ListModel;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
import stendcontrol.ExperimentContainer;

/**
 *
 * @author minaev
 */
public class ExperimentListModel implements ListModel<String> {
    
    ExperimentContainer ec;
    ArrayList<ListDataListener> listeners = new ArrayList<ListDataListener>();

    public ExperimentListModel(ExperimentContainer ec) {
        this.ec = ec;
    }
    
    public void updateList(){
        ListDataEvent lde = new ListDataEvent(this, ListDataEvent.CONTENTS_CHANGED, 0, this.getSize()-1);
        for(int i=0;i<listeners.size();i++){
            listeners.get(i).contentsChanged(lde);
        }
    }

    @Override
    public int getSize() {
        return ec.getSize();
    }

    @Override
    public String getElementAt(int index) {
        return ec.getExp(index).getExpName();
    }

    @Override
    public void addListDataListener(ListDataListener l) {
        listeners.add(l);
    }

    @Override
    public void removeListDataListener(ListDataListener l) {
        listeners.remove(l);
    }
    
}
